﻿/*
Copyright (c) 2008 William Duff

Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Text;

namespace LiveUpload.Facebook
{
    public class Friend : IComparable<Friend>
    {
        #region Constructors

        /// <summary>
        /// Default constructor creates an empty Friend object.
        /// </summary>
        public Friend()
        {
            this.firstName = string.Empty;
            this.lastName = string.Empty;
            this.uid = string.Empty;
            this.squarePictureUrl = string.Empty;
        }

        /// <summary>
        /// Constructs a Friend object to represent user's friend.
        /// </summary>
        public Friend(string name, string uid, string squarePictureUrl)
        {
            this.firstName = name;
            this.lastName = string.Empty;

            // Try and guess the first name from the last name.
            int spaceIndex = name.LastIndexOf(' ');
            if (spaceIndex >= 0)
            {
                this.firstName = name.Substring(0, spaceIndex);
                this.lastName = name.Substring(spaceIndex + 1);
            }

            this.uid = uid;
            this.squarePictureUrl = squarePictureUrl;
        }

        /// <summary>
        /// Constructs a Friend object to represent user's friend.
        /// </summary>
        public Friend(string firstName, string lastName, string uid, string squarePictureUrl)
        {
            this.firstName = firstName;
            this.lastName = lastName;
            this.uid = uid;
            this.squarePictureUrl = squarePictureUrl;
        }

        #endregion

        #region Private Fields

        private string firstName;
        private string lastName;
        private string uid;
        private string squarePictureUrl;

        #endregion

        #region Public Fields

        /// <summary>
        /// First name of the friend
        /// </summary>
        public string FirstName
        {
            get { return this.firstName; }
        }

        /// <summary>
        /// Last name of the friend
        /// </summary>
        public string LastName
        {
            get { return this.lastName; }
        }

        /// <summary>
        /// Full name of the friend
        /// </summary>
        public string Name
        {
            get { return (this.firstName + " " + this.lastName).Trim(); }
        }

        /// <summary>
        /// UID of the friend
        /// </summary>
        public string UID
        {
            get { return this.uid; }
        }

        /// <summary>
        /// A URL of a square profile picture for the user.
        /// </summary>
        public string SquarePictureUrl
        {
            get { return this.squarePictureUrl; }
            set { this.squarePictureUrl = value; }
        }

        /// <summary>
        /// Creates a textual representation of the object.
        /// </summary>
        /// <returns>
        /// The name of the Friend.
        /// </returns>
        public override string ToString()
        {
            return this.Name;
        }

        #endregion

        #region IComparable<Friend> Members

        public int CompareTo(Friend other)
        {
            return String.Compare(this.Name, other.Name, true);
        }

        #endregion
    }
}
